<!DOCTYPE html>
<html>
<head>
<div th:include="base-libs :: base-libs" />
</head>
<script th:src="'/service/js/jtqy.js'"></script>
<title>续约-弹窗</title>

<style>
.layui-form-select {
    width: 80%;
}
#tbody tr td {
	height: 30px;
	padding: 0.4px 10px;
}
.layui-table th{
	padding: 6px 10px;
}
#tbody .layui-input{
	height: 28px;
}
</style>
<script th:inline="javascript">
	/**读取request中的初始化数据*/
	var result = [[${DATA}]];
</script>

<script type="text/javascript">
var bgfwbInfo = StoreCache.removeCache("JTQYXYINFO");
	$(function(){
		var JMXXIDS = [];
		var FWBIDS = [];
		var FWBSX = [];
		var QYXXIDS = [];
		$("#JLS").find("span").eq(0).html(bgfwbInfo.length).end().eq(1).html(bgfwbInfo[0].TDMC);
		for(var i = 0; i < bgfwbInfo.length ; i ++){
			var row = bgfwbInfo[i];
			FWBIDS.push(row["FWBID"]);
			JMXXIDS.push(row["JMXXID"]);
			FWBSX.push(row["FWBSX"]);
			QYXXIDS.push(row["QYXXID"]);
			//结束日期
		    var endTime = stringToJsTime_(row["JSSJ"])
		    endTime.setDate(endTime.getDate() + 1);
			var endTimeObj = {
					elem : "#" + row["QYXXID"] + "jssj",
	    			min : endTime.format('yyyy-MM-dd'),
                	istoday: false,
	    		  	choose: function(datas){
	    		  		startTimeObj.max = datas;
	    		    }
	    	};
	    	//生效日期
	    	var startTime = stringToJsTime_(row["SXSJ"])
		    startTime.setDate(startTime.getDate() + 1);
	    	var startTimeObj = {
	    		elem : "#" + row["QYXXID"] + "kssj",
	    		 min : startTime.format('yyyy-MM-dd'),
	    		 max : endTime.format('yyyy-MM-dd'),
                istoday: false,
	    		 choose: function(datas){
	    			 endTimeObj.min = datas;
	    		 }
	    	};
		    var tr = $("<tr>").addClass("item");
		    var td1 = $("<td>").html(row["XM"]);
		    var td2 = $("<td>").html(row["FWBMC"]);
		    var td3 = $("<td>").html(cutDate_YYYYMMDD(row["SXSJ"]));
		    var td4 = $("<td>").html(cutDate_YYYYMMDD(row["JSSJ"]));
		    var td5 = $("<td>");
		    var td6 = $("<td>");
		    var kssj = $("<input>").attr({type:"text",id:row["QYXXID"] + "kssj", readonly:"readonly","autocomplete":"off",
		    		"quick-config":"label:'签约日期', validateProxy:'notNull length', length: '16'" })
		    		.addClass("laydate-icon layui-input dataField").val(endTime.format('yyyy-MM-dd'));
		    td5.append(kssj);
		    endTime.setFullYear(endTime.getFullYear()+1);
		    endTime.setDate(endTime.getDate() - 1);
		    var jssj = $("<input>").attr({type:"text",id:row["QYXXID"] + "jssj",readonly:"readonly","autocomplete":"off",
	    		"quick-config":"label:'结束日期', validateProxy:'notNull length', length: '16'" })
	    		.addClass("laydate-icon layui-input dataField").val(endTime.format('yyyy-MM-dd'));
		    td6.append(jssj);
			tr.append(td1,td2,td3,td4,td5,td6);
			$("#tbody").append(tr);
	    	laydate(startTimeObj);
	    	laydate(endTimeObj);
		}
		//$("#QYBMC").val(value);
		layui.use('form', function(){
			  var form = layui.form();
			  form.on('submit(formDemo)', function(data){
				  if($(".dataField").QuickValidate()){
					  var xysjAry = [];
					  $("#tbody tr").each(function(){
						  var xysj = [];
						  $(this).find("input").each(function(){
							  xysj.push($(this).val());
						  });
						  xysjAry.push(xysj.join(","));
					  });
					  
					  var params = {
						 FWBIDS : FWBIDS.join("|"),
						 TDID : bgfwbInfo[0].YLTDID,
						 YLJGID : bgfwbInfo[0].YLJGID,
						 JMXXIDS : JMXXIDS.join(","),
						 XYSJARY : xysjAry.join("|"),
						 FWBSX : FWBSX.join("|"),
						 QYXXIDS:QYXXIDS.join(",")
					  }
					 var bgfwburl = $.QuickUrlUtils.getProjectName()+"/jtqy/"
						$.QuickRemote.AjaxJson(bgfwburl + "plxyfw",function(result){
							if (result["state"]) {
							   $.QuickAlert.alertNormal("续约服务成功！",{callback: function(){
								   StoreCache.setCache("JTQY_OPT_SUCCESS", "true");
								   parent.layer.closeAll();
								}});
							} else {
								$.QuickAlert.alertFail({
									content : info["faultInfo"]
								});
								return ;
							}
						},params);
				  }
			  });
		});
	});
	
	function backFun(){
		parent.layer.closeAll();
	}
	
	/** 时间截取  */
	function cutDate_YYYYMMDD(date){
		if(!StringUtils.isEmpty(date)){
			return date.substring(0,10);
		}
	}
</script>

<body class="easyui-layout" fit="true" border="false">
<div region="center" style="height:150px;">
	<div class="layui-form" >
		<div class="layui-form-mid" id="JLS" style="font-size: 14px;margin-left: 10px;">您选中了<span style="color: #FF0000">9</span>条记录，签约团队为<span style="color: #FF0000">芦医生团队</span>，请您确认以下续约信息：</div>
		 <table class="layui-table">
		  <colgroup>
		    <col width="100">
		    <col width="150">
		    <col width="100">
		    <col width="100">
		    <col width="150">
		    <col width="150">
		  </colgroup>
		  <thead>
		    <tr>
		      <th>姓名</th>
		      <th>签约服务包</th>
		      <th>签约开始日期</th>
		      <th>签约结束日期</th>
		      <th>续约开始日期</th>
		      <th>续约结束日期</th>
		    </tr> 
		  </thead>
		  <tbody id="tbody">
		    
		  </tbody>
		</table> 
		
	</div>
	</div>
	<div region="south" style="height:40px;line-height:40px">
	<div class="layui-form-item" style="position: absolute;width: 100%;margin-bottom: 0px;bottom: 0px;text-align: center;">
			<div class="layui-btn" lay-submit lay-filter="formDemo" style="margin-left: 0px;">提交</div>
			<button type="reset" class="layui-btn layui-btn-primary" onclick="backFun()">返回</button>
		</div>
	</div>
</body>
</html>
